﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace SpriteSample
{
    enum eStatus
    {
        Standing,
        Walking,
        Jumping,
        Attacking
    };
    enum eSpecies
    {
        Player,
        TitleObject,
        Monster_1,
        Monster_2,
        Boss
    };
    enum eDirFace
    {
        Right,
        Left
    };
    enum eDirConllision
    {
        None, //khong va cham
        Right,
        Left,
        Up,
        Down
    };
    
    class Object
    {
        //dung chung cho tat ca object
        public eSpecies m_eSpecies; //phan loai object
        public eStatus m_eStatus;   //trang thai object
        public eDirFace m_eDirFace; //huong
        public eDirConllision m_eDirCol;
        public Vector2 m_vPos;      //vi tri
        public Vector2 m_vVecloc;   //van toc
        public Vector2 m_vAccloc;   //gia toc
        public Vector2 m_vSize;
        public KeyInput m_keyInput;
        public Sprite m_currSprite;
        public Object(float _posX, float _posY)
        {
            m_vPos = new Vector2(_posX, _posY);
            m_vVecloc = Vector2.Zero;
            m_eStatus = eStatus.Standing;
            m_keyInput = new KeyInput();
        }
        public Object(Object _copy)
        {
            m_vPos = _copy.m_vPos;
            m_vVecloc = _copy.m_vVecloc;
            m_eStatus = eStatus.Standing;
            m_keyInput = new KeyInput();
        }
        virtual public Rectangle Bound
        {
            get
            {
                Rectangle _Rect;
                //_Rect.X = (int)m_vPos.X;
                //_Rect.Y = (int)m_vPos.Y;

                _Rect.X = (int) m_currSprite.Position.X;
                _Rect.Y = (int) m_currSprite.Position.Y;

                //_Rect.Width = (int)m_vSize.X;
                //_Rect.Height = (int)m_vSize.Y;

                _Rect.Width = (int) m_currSprite.Width;
                _Rect.Height = (int) m_currSprite.Height;
                return _Rect;
            }
        }
        virtual public void UpdateCollision(List<Object> _listObject)
        {

        }

        public eDirConllision CheckCollision(Object _Obj1, Object _Obj2)
        {
            if (_Obj1.Bound.Intersects(_Obj2.Bound))
            {
                float top = Math.Abs(_Obj1.Bound.Top - _Obj2.Bound.Bottom);
                float botom = Math.Abs(_Obj1.Bound.Bottom - _Obj2.Bound.Top);
                float left = Math.Abs(_Obj1.Bound.Left - _Obj2.Bound.Right);
                float right = Math.Abs(_Obj1.Bound.Right - _Obj2.Bound.Left);
                float rs = Math.Min(Math.Min(right, left), Math.Min(top, botom));

                if (rs == top)
                {
                    return eDirConllision.Up;
                }
                if (rs == botom)
                {
                    return eDirConllision.Down;
                }
                if (rs == left)
                {
                    return eDirConllision.Left;
                }
                if (rs == right)
                {
                    return eDirConllision.Right;
                }
            }
            return eDirConllision.None;
        }
        virtual public void LoadContent(ContentManager _contentManager)
        {
            
        }

        virtual public void Update(GameTime gameTime)
        {
            
        }
        virtual public void Render(GameTime gameTime, SpriteBatch _spriteBatch)
        {
            
        }

    }
}
